
export default class xEvent {

	static getInstance() {
		if(!this.instance) {
			this.instance = new xEvent();
		}
		return this.instance;
	}

    static dispatch(type,key,el,data){
    	let eventType = key?type+'.'+key:type;
    	let e = new CustomEvent(eventType, {
			detail:data
		});
		if(el){
		   if(el.dispatchEvent)
		       el.dispatchEvent(e);
		   else
		       el.fireEvent(e);
        }else{
            if(window.dispatchEvent) {
                window.dispatchEvent(e);
            } else {
                window.fireEvent(e);
            }
        }


    }
    
	static DataRequire(key, param){
		xEvent.dispatch('DataRequire',key,param);
	}

	static DataReady(key,data) {
		xEvent.dispatch('DataReady',key,data);
	}
	
	static RequestOver(key,el,data) {
		xEvent.dispatch('RequestOver',key,el,data);
	}
}